home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** **
- ** Module: Text3D.c **
- ** **
- ** **
- ** Purpose: Create a general polygon from character outlines **
- ** **
- ** **
- ** **
- ** Copyright (C) 1992-1995 Apple Computer, Inc. All rights reserved. **
- ** **
- ** **
- *****************************************************************************/
- #include "QD3D.h"
- #include "Text3D.h"
-
- #if defined(NOGX) && NOGX
-
- TQ3GroupObject ReadText(
- void)
- {
- return(NULL);
- }
-
- TQ3GroupObject MakeText(
- char *str)
- {
- return (NULL);
- }
-
- #else /* !defined(NOGX) || !NOGX */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- #include <Dialogs.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <OSUtils.h>
- #include <SegLoad.h>
- #include <TextEdit.h>
- #include <Files.h>
- #include <StandardFile.h>
-
- #ifdef applec
- # include <Strings.h>
- #endif /* applec */
- #ifdef THINK_C
- # include <pascal.h>
- #endif /* THINK_C */
-
- #include "QD3DShader.h"
- #include "QD3DTransform.h"
- #include "QD3DStyle.h"
- #include "QD3DView.h"
- #include "QD3DMath.h"
- #include "QD3DSet.h"
- #include "QD3DGroup.h"
- #include "QD3DGeometry.h"
-
- #include "font library.h"
- #include "graphics libraries.h"
- #include "graphics routines.h"
- #include "graphics toolbox.h"
-
- /*
- * This needs to be after all Escher and toolbox includes
- */
- #include "math routines.h"
- #include "offscreen library.h"
- #include "storage library.h"
-
- #include "layout types.h"
- #include "layout routines.h"
- #include "layout feature constants.h"
-
-
- /*===========================================================================*\
- *
- * Routine: ReadText()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- TQ3GroupObject ReadText(
- void)
- {
- char str[256];
-
- TextFont(symbol);
- TextFace(italic);
- TextSize(9);
- TextMode(srcCopy);
-
- strcpy(str, "QuickDraw 3D");
- return(MakeText(str));
- }
-
-
- /*===========================================================================*\
- *
- * Routine: MakeText()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- TQ3GroupObject MakeText(
- char *str)
- {
- gxPoint strPosition;
- gxShape stringShape;
- long size, numContours;
- gxPolygons *blog;
- gxPolygon *poly;
- char *pp;
- unsigned long i, b, c;
-
- TQ3GroupObject group;
- TQ3ColorRGB col;
- gxRectangle rect = {
- IntToFixed(0.0),
- IntToFixed(0.0),
- IntToFixed(100.0),
- IntToFixed(-100.0)
- };
- gxRectangle rect2 = {
- IntToFixed(30.0),
- IntToFixed(-30.0),
- IntToFixed(60.0),
- IntToFixed(-60.0)};
-
-
- TQ3GeneralPolygonData gp;
- TQ3GeometryObject generalPoly;
-
- gxRunFeature features[1];
-
- strPosition.x = 0;
- strPosition.y = 0;
- stringShape = NewCString(str, &strPosition);
- GXSetShapeFont(stringShape, FindCNameFont(gxFamilyFontName, "Apple Chancery"));
- GXSetShapeTextSize(stringShape, IntToFixed(48));
- GXSetShapeFill(stringShape, gxSolidFill);
-
- GXSetShapeType(stringShape, gxLayoutType);
- features[0].featureType = designComplexityType;
- features[0].featureSelector = designLevel3Selector;
- GXSetShapeRunFeatures(stringShape, 1, features);
-
- GXSetStyleCurveError(GXGetShapeStyle(stringShape), FloatToFixed(1.5));
- GXSetShapeCurveError(stringShape, FloatToFixed(1.5));
-
- GXSetShapeType(stringShape, gxPolygonType);
-
- numContours = GXCountShapeContours(stringShape);
- size = GXGetPolygons(stringShape, NULL);
- if (!(blog = (gxPolygons *) malloc (size))) {
- return(NULL);
- }
- GXGetPolygons(stringShape, blog);
- GXDisposeShape(stringShape);
-
- group = Q3OrderedDisplayGroup_New();
- Q3ColorRGB_Set(&col, 1.0, 0.0, 0.0);
-
- #if 0
- gp.numContours = blog->contours;
- gp.generalPolygonAttributeSet = Q3AttributeSet_New();
-
- Q3AttributeSet_Add(
- gp.generalPolygonAttributeSet,
- kQ3AttributeTypeDiffuseColor,
- (const void *) &col);
-
- if (!(gp.contours =
- (TQ3GeneralPolygonContourData *) malloc(gp.numContours * sizeof(TQ3GeneralPolygonContourData)))) {
- return(NULL);
- }
-
- pp = (char *)&blog->contour[0].vectors;
- for (i = 0; i < blog->contours; i++) {
- poly = (gxPolygon *)pp;
- pp += sizeof(long);
- gp.contours[i].numVertices = poly->vectors;
-
- if (!(gp.contours[i].vertices = (TQ3Vertex3D *)
- malloc(poly->vectors * sizeof(TQ3Vertex3D)))) {
- return (NULL);
- }
-
- for (b = 0, c = poly->vectors-1; b < poly->vectors; b++, c--) {
- gp.contours[i].vertices[c].point.x =
- (float)FixedToFloat(poly->vector[b].x) / 20.0;
- gp.contours[i].vertices[c].point.y =
- (float)-FixedToFloat(poly->vector[b].y) / 20.0;
- gp.contours[i].vertices[c].point.z = 0.0;
- gp.contours[i].vertices[c].attributeSet = NULL;
- pp += sizeof(gxPoint);
- }
- }
-
- generalPoly = Q3GeneralPolygon_New(&gp);
- Q3Group_AddObject(group, generalPoly);
-
- Q3Object_Dispose(gp.generalPolygonAttributeSet);
- Q3Object_Dispose(generalPoly);
-
- for (i = 0; i < blog->contours; i++) {
- free(gp.contours[i].vertices);
- }
- free(gp.contours);
- #else
- {
- TQ3MeshFace frontSideFace = NULL, backSideFace = NULL;
- TQ3MeshVertex previousFront = NULL, previousBack = NULL;
- long numVertices = 0;
- TQ3MeshVertex *firstFrontVertex, *frontVertices, *firstBackVertex, *backVertices;
- TQ3MeshVertex sideFace[4] = {0, 0, 0, 0};
-
- pp = (char *)&blog->contour[0].vectors;
-
- /*
- for (i = 0; i < blog->contours; i++) {
- poly = (gxPolygon *)pp;
- numVertices += poly->vectors;
- pp += sizeof(long) + poly->vectors * 2 * sizeof(long);
- }
- */
-
- pp = (char *)&blog->contour[0].vectors;
-
- for (i = 0; i < blog->contours; i++) {
- TQ3GeometryObject textMesh = Q3Mesh_New();
-
- Q3Mesh_DelayUpdates(textMesh);
-
- poly = (gxPolygon *)pp;
- pp += sizeof(long);
-
- if (!(frontVertices = (TQ3MeshVertex *)
- malloc(poly->vectors * sizeof(TQ3MeshVertex))) ) {
- return NULL;
- }
-
- firstFrontVertex = frontVertices;
-
- if (!(backVertices = (TQ3MeshVertex *)
- malloc(poly->vectors * sizeof(TQ3MeshVertex))) ) {
- return NULL;
- }
-
- firstBackVertex = backVertices;
-
- for (b = 0, c = poly->vectors-1; b < poly->vectors; b++, c--) {
- TQ3Vertex3D vertex;
-
- vertex.point.x = (float)FixedToFloat(poly->vector[b].x) / 20.0;
- vertex.point.y = (float)-FixedToFloat(poly->vector[b].y) / 20.0;
- vertex.point.z = 0.0;
- vertex.attributeSet = NULL;
-
- *frontVertices = Q3Mesh_VertexNew(textMesh, &vertex);
- if( *frontVertices == NULL) {
- return NULL;
- }
-
- vertex.point.z = 5.0;
- *backVertices = Q3Mesh_VertexNew(textMesh, &vertex);
- if( *backVertices == NULL) {
- return NULL;
- }
-
- if( sideFace[0] && sideFace[1]) {
- sideFace[2] = *backVertices;
- sideFace[3] = *frontVertices;
- Q3Mesh_FaceNew(textMesh, 4,sideFace,NULL);
- }
-
- sideFace[0] = *frontVertices;
- sideFace[1] = *backVertices;
-
- frontVertices++;
- backVertices++;
-
- pp += sizeof(gxPoint);
- }
- Q3Mesh_FaceNew(textMesh, poly->vectors,firstFrontVertex,NULL);
- Q3Mesh_FaceNew(textMesh, poly->vectors,firstBackVertex,NULL);
-
- free(firstFrontVertex); free(firstBackVertex);
-
- Q3Group_AddObject(group, textMesh);
-
- Q3Object_Dispose(textMesh);
- }
-
- /*
- for (i = 0; i < blog->contours; i++) {
- free(gp.contours[i].vertices);
- }
- free(gp.contours);
- */
- }
- #endif
- return(group);
- }
-
- #endif /* defined(NOGX) && NOGX */
-